package lz.controls
{
	import com.common.utils.DisplayObjectUtil;
	import com.greensock.TweenLite;
	
	import flash.display.Shape;
	import flash.text.TextField;
	
	import lz.controls.core.UIComponent;

	/**
	 * 文字显示，长度不够可支持滚动
	 * //txtUserName 为flash cs 工具 或者 代码 创建的文本实例
	 *	var lLabel :LLabel = new LLabel();
	 *	lLabel.x = txtUserName.x;
	 *	lLabel.y = txtUserName.y;
	 *	lLabel.textField = txtUserName;
	 *	lLabel.width = 71;//要显示的宽度
	 *	lLabel.height = 20;
	 *	this.addChild(lLabel);
	 *	lLabel.text = "社会主义新中国面貌";//实际文本，textWidth 可能大于 width，则滚动
	 * 
	 *  @author lake
	 */	
	public class LLabel extends UIComponent
	{
		/**
		 * 文本
		 */		
		protected var mTextField :TextField;
		
		public function LLabel()
		{
			super();
		}
		/**
		 * 
		 * 
		 */		
		override protected function configUI():void
		{
			super.configUI();
		}
		/**
		 * set textField
		 * @param value
		 * 
		 */		
		public function set textField(value :TextField):void
		{
			mTextField = value;
			if(mTextField == null)return;
			this.addChild(mTextField);
			mTextField.x = 0;
			mTextField.y = 0;
		}
		/**
		 * get textField
		 * @return 
		 * 
		 */		
		public function get textField():TextField
		{
			return mTextField;
		}
		/**
		 * set height
		 * @param value
		 * 
		 */		
		override public function set height(value:Number):void
		{
			super.height = value;
		}
		/**
		 * set width
		 * @param value
		 * 
		 */		
		override public function set width(value:Number):void
		{
			super.width = value;
		}
		/**
		 * get text
		 * @return 
		 * 
		 */		
		public function get text():String 
		{
			return mTextField.text;
		}
		/**
		 * set text
		 * @param value
		 */		
		public function set text(value:String):void 
		{
			if (value == text) 
			{ 
				return;
			}
			mTextField.text = value;
			var tempW :Number = (mTextField.textWidth + 5);
			if(tempW > width)
			{
				mTextField.width = tempW;
				scrollX();
			}
		}
		/**
		 * get htmlText
		 * @return 
		 * 
		 */		
		public function get htmlText():String 
		{
			return mTextField.htmlText;
		}
		/**
		 *set htmlText 
		 * @param value
		 * 
		 */		
		public function set htmlText(value:String):void 
		{
			if (value == htmlText)
			{ 
				return;
			}
			mTextField.htmlText = value;
			mTextField.width = mTextField.textWidth + 5;
			if(mTextField.width > width)
			{
				scrollX();
			}
		}
		/**
		 * scrollX
		 * 水平滚动
		 */		
		private function scrollX():void
		{
			var markSp :Shape = new Shape();
			markSp.graphics.beginFill(0x000000);
			markSp.graphics.drawRect(0,0,width,height);
			markSp.graphics.endFill();
			this.addChild(markSp);
			this.mask = markSp;
			scrollXComplete(width - mTextField.width);
		}
		private function scrollXComplete(targetX :Number):void
		{
			TweenLite.to(mTextField,2,{x:targetX,onComplete:scrollXComplete,delay:1,onCompleteParams:[width - mTextField.width - targetX]});
		}
		/**
		 * destroy
		 * 
		 */		
		override public function destroy():void
		{
			super.destroy();
			DisplayObjectUtil.removeAllChildren(this);
			TweenLite.killTweensOf(mTextField);
			mTextField = null;
		}
	}
}